//1. 引入 axios
import axios from 'axios';
// nprogress 导入包
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import { toast } from "react-toastify";

//2. 创建实例对象
let instance = axios.create({
    baseURL: 'http://localhost:3001'
});

//3. 设置拦截器
instance.interceptors.request.use(config => {
    NProgress.start();
    //返回配置对象
    return config;
});

instance.interceptors.response.use(res => {
    NProgress.done();
    return res.data;
}, err => {
    toast.error('请求异常, 请稍后再试!!', {
        position: toast.POSITION.TOP_CENTER,
    });
    //返回 pending 状态的 promise
    return new Promise(() => {});
});

//暴露
export default instance;